import vue from 'vue'
import vuex from 'vuex'
vue.use(vuex)
export const store = new vuex.Store({//按名导出
  state:{
    products:[
      { name : "马云" , price : '1000' },
      { name : "马化腾" , price : '500' },
      { name : "马冬梅" , price : '200' },
      { name : "马荣" , price : '100' },
    ]
  },
  getters:{
    getpro(state){
      return state.products
    }
  },
  mutations:{
    reduce(state,playLoad){
      state.products.forEach(item => {
        return item.price = item.price -= playLoad
      })
    }
  },
  actions:{
    reducePrice(context,playLoad){
      setTimeout(() => {
      context.commit('reduce',playLoad)
        
      }, 1000);
    }
  }
  
})
// export  store;